package com.wm.web.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.interceptor.SessionAware;

import com.wm.bean.Area;
import com.wm.bean.City;
import com.wm.bean.UserScriptorium;
import com.wm.comm.Constant;
import com.wm.comm.PinYinUtil;
import com.wm.service.AreaService;
import com.wm.service.CityService;
import com.wm.service.UserScriptoriumService;
import com.wm.service.web.PageList;
import com.wm.service.web.Pages;
import com.wm.web.ui.OptionsInt;
import com.wm.web.ui.OptionsLong;

public class AdminUserScriptorium extends BaseAction{
	private static final Log logger = LogFactory.getLog(AdminUserScriptorium.class);
	
	private UserScriptoriumService userScriptoriumService;

	public UserScriptoriumService getUserScriptoriumService() {
		return userScriptoriumService;
	}

	public void setUserScriptoriumService(
			UserScriptoriumService userScriptoriumService) {
		this.userScriptoriumService = userScriptoriumService;
	}
	
	private List addTypeList = new ArrayList();

	public List getAddTypeList() {
		return addTypeList;
	}

	public void setAddTypeList(List addTypeList) {
		this.addTypeList = addTypeList;
	}
	
	private void setAddTypeListValues(){
		addTypeList = Constant.SCRIPTORIUM_TYPE;
	}
	

	private long id;					//主键ID

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}
	
	private PageList pageList;
	
	public PageList getPageList() {
		return pageList;
	}

	public void setPageList(PageList pageList) {
		this.pageList = pageList;
	}	

	public String execute() {
		try {
			return this.executeMethod(this.getAction());
		} catch (Exception e) {
			logger.error(e);
			return INPUT;
		}
	}

	/**
	 * 初始页
	 */
	public String index(){
		Pages pages = new Pages();
		pages.setPage(this.getPage());
		pages.setPerPageNum(Constant.PAGE_NUM);
		if (this.getTotal() > 0) {
			pages.setTotalNum(this.getTotal());
		}
		pages.setFileName("/admin_user_scriptorium.action");
		this.setPageList(this.getUserScriptoriumService().findUserScriptoriums("id", 1, pages));
		return SUCCESS;
	}
	
	public String del(){
		this.getUserScriptoriumService().removeUserScriptoriumById(id);
		return "index";
	}
	
	public String updateverify(){
		UserScriptorium us = this.getUserScriptoriumService().findUserScriptoriumById(this.id);
		int isVerify = us.getIsVerify();
		isVerify = Math.abs(isVerify-1);
		us.setIsVerify(isVerify);
		this.getUserScriptoriumService().updateUserScriptorium(us);
		return "index";
	}

}
